package com.workday.gridsimulator

/**
 * First in First Out Allocator
 * 
 * Implements the WorkAllocator trait in a first in first out manner
 * 
 */
class FifoAllocator extends WorkAllocator {
  
  override def name = "fifo workallocator"
    
  private var workQueue : List[Work] =  List()
  
  /**
   * @param work the work to add to the queue
   * 
   * Adds the work parameter to the end of the current work queue
   */
  override def +=(work : Work) : Unit = {
    workQueue = workQueue ::: List(work)
  }

  /**
   * @param thatWorkQueue a list of work to be added to the queue
   * 
   * Adds the list parameter to the end of the current queue
   */
  override def +=(thatWorkQueue : List[Work]) : Unit = { 
	workQueue = workQueue ::: thatWorkQueue
  }

  override def isEmpty : Boolean = workQueue.isEmpty
	
  override def reset = workQueue = List()
  
  /**
   * Pops off the work item at the top of the queue.
   * 
   */
  override def getWorkItem : Work =  {
    val work = workQueue.head
    workQueue = workQueue.tail
    work
  }
  
  override def getItemsLeft = workQueue.size
  
}